package ru.nsu.fit.iconveyor.engine.smart;

import ru.nsu.fit.iconveyor.conveyor.channel.Channel;
import ru.nsu.fit.iconveyor.engine.exception.ChannelOverflowException;

import java.util.LinkedList;
import java.util.Queue;

public class SimpleChannel<T> extends Channel<T> {
    private Queue<T> dataQueue = new LinkedList<T>();

    public SimpleChannel(String id) {
        super(id);
    }

    public void add(T data) throws ChannelOverflowException {
        try {
            dataQueue.add(data);
        } catch (IllegalStateException e) {
            throw  new ChannelOverflowException("channel overflow", e);
        }
    }

    public T poll() {
        return dataQueue.poll();
    }

    public T peek() {
        return dataQueue.peek();
    }

    @Override
    public boolean isEmpty() {
        return dataQueue.isEmpty();
    }
}
